package com.light.applet.common.utils;

import cn.hutool.core.bean.BeanUtil;
import com.light.applet.common.entity.Account;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;


/**
 * @author: 魏彪
 */
public class UserUtils {

    public static Account currentUser() {
        OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
        Object details = oAuth2Authentication.getUserAuthentication().getDetails();
        return BeanUtil.toBean(BeanUtil.beanToMap(details).get("principal"), Account.class);
    }
}
